/*
 Copyright (c) 2014, Carlos Eduardo Klock.
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
 materials provided with the distribution.

 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific
 prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.googlecode.fxutils;

import javafx.geometry.Insets;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Modality;
import javafx.stage.StageStyle;
import javafx.stage.Window;

/**
 * Class to hold dialog properties. This class uses the Builder pattern to
 * create properties. See the static builder method.
 *
 * @see DialogProperties#builder(javafx.stage.Window)
 * @see http://jlordiales.wordpress.com/2012/12/13/the-builder-pattern-in-practice/
 *
 * @author Carlos Eduardo Klock
 * @since 04/2014
 */
public final class DialogProperties {

    private final Window ownerWindow;
    private final boolean centralizeOnOwner;
    private final Modality modality;
    private final StageStyle decoration;
    private final String title;
    private final Font font;
    private final String css;
    private final Insets padding;

    private DialogProperties(final Builder builder) {
        this.ownerWindow = builder.ownerWindow;
        this.centralizeOnOwner = builder.centralizeOnOwner;
        this.modality = builder.modality;
        this.decoration = builder.decoration;
        this.title = builder.title;
        this.font = builder.font;
        this.css = builder.css;
        this.padding = builder.padding;
    }

    /**
     * Creates new builder.
     * @param owner  the owner window. Can't be null.
     * @return new builder.
     * @see http://jlordiales.wordpress.com/2012/12/13/the-builder-pattern-in-practice/
     */
    public static Builder builder(final Window owner) {
        return new Builder(owner);
    }

    /**
     * Creates default properties.
     * @param owner  the owner window.
     * @return default dialog properties.
     */
    public static DialogProperties getDefault(final Window owner) {
        return builder(owner).build();
    }

    public Window getOwnerWindow() {
        return ownerWindow;
    }

    public boolean isCentralizeOnOwner() {
        return centralizeOnOwner;
    }

    public Modality getModality() {
        return modality;
    }

    public StageStyle getDecoration() {
        return decoration;
    }

    public String getTitle() {
        return title;
    }

    public Font getFont() {
        return font;
    }

    public String getCss() {
        return css;
    }

    public Insets getPadding() {
        return padding;
    }

    public static final class Builder {
        private final Window ownerWindow;
        private boolean centralizeOnOwner = true;
        private Modality modality = Modality.APPLICATION_MODAL;
        private StageStyle decoration = StageStyle.UTILITY;
        private String title = "";
        private Font font = Font.font("System", FontWeight.NORMAL, 14);
        private String css = "-fx-background-color:cornsilk;";
        private Insets padding = new Insets(10);

        /**
         * Creates a new DialogProperties builder.
         * @param ownerWindow  the owner of the dialog.
         */
        private Builder(final Window ownerWindow) {
            if (ownerWindow == null) {
                throw new NullPointerException("Owner window can't be null!");
            }
            this.ownerWindow = ownerWindow;
        }

        /**
         * @param centralizeOnOwner  defines if the dialog will be centralized on the owner when displayed.
         * @return
         */
        public Builder centralizeOnOwner(boolean centralizeOnOwner) {
            this.centralizeOnOwner = centralizeOnOwner;
            return this;
        }

        /**
         * @param modality     the modality of the dialog.
         * @return
         */
        public Builder modality(Modality modality) {
            this.modality = modality;
            return this;
        }

        public Builder decoration(StageStyle decoration) {
            this.decoration = decoration;
            return this;
        }

        /**
         * @param title     title of the dialog.
         * @return
         */
        public Builder title(String title) {
            this.title = title;
            return this;
        }

        public Builder font(Font font) {
            this.font = font;
            return this;
        }

        public Builder css(String css) {
            this.css = css;
            return this;
        }

        public Builder padding(Insets padding) {
            this.padding = padding;
            return this;
        }

        public DialogProperties build() {
            return new DialogProperties(this);
        }

    }

}
